package com.edusite
import com.edusite.Logbook

class LogbookFilters {
    
    def twitterService

    def filters = {
        all(controller:'*', action:'*') {
            before = {
         
              if(session.log) {
             def miLogbook = Logbook.get(session.log.id)
              miLogbook.salida= new Date()
              miLogbook.tarea=controllerName+" "+actionName
              assert miLogbook.save() // comprobar que funciona con el assert
              
              if (!twitterService.loggedIn) {
                  twitterService.login("enteducativo", "educativo", request, response)
                  }
              def ipRemota = request.getRemoteAddr().toString() 
//              def hostRemoto= request.getRemoteHost()   
              def twitterMess = miLogbook.salida.toString()+" "+ session.user+" " + miLogbook.tarea + " " + ipRemota + "@itubal"
//              twitterService.setStatus twitterMess
 //               twitterService.sendMessage "enteducativo",miLogbook.tarea  
                 
                  
              }              
            }
            after = {
                
            }
            afterView = {
                
            }
        }
    }
    
}
